package assignment.ton.jenerator;
import java.util.ArrayList;
import assignment.ton.def.Class;
import assignment.ton.def.Variable;
/**
 * Class for creating variable code 
 * @author Tim
 * Creates the code for variables when passed a class object.
 */
public class VarJen {
	private Class theClass;
	public VarJen(Class c){
		theClass = c;
	}
	public String[] getOutput(){
		String[] data;
		ArrayList<Variable> varList = theClass.getVariableArrayList();
		if(varList.size()>0){
			data = new String[varList.size()];
			for(int i = 0; i<varList.size(); i++){
				if(varList.get(i).isMany()==false){
					String initialVal = "";
					if(varList.get(i).getDefaultValue().equals("")==false){
						String initialData = varList.get(i).getDefaultValue();
						if(varList.get(i).getType().equals("String")){
							initialData = "\""+initialData+"\"";
						}
						if(varList.get(i).getType().equals("char")){
							initialData = "\'"+initialData+"\'";
						}
						initialVal = " = "+initialData;
					}
					data[i] = "\tprivate "+varList.get(i).getType()+" "+varList.get(i).getName()+initialVal+";";
				}else{
					data[i] = "\tprivate ArrayList<"+varList.get(i).getType()+"> "+varList.get(i).getName()+" = new ArrayList<"+varList.get(i).getType()+">();";
				}
			}
		}else{ 
			data = new String[1]; 
			data[0] = "";
		}
		return data;
	}
}
